<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="时间（月）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="date">
              <j-date :disabled=formDisabled placeholder="请选择时间（月）" v-model="model.date"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="员工名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employeeId">
              <a-input :disabled=formDisabled v-model="model.employeeId" placeholder="请输入员工名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属组织" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="departId">
              <a-input :disabled=formDisabled v-model="model.departId" placeholder="请输入所属组织"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="职务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="postId">
              <a-input :disabled=formDisabled v-model="model.postId" placeholder="请输入职务"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="正常打开次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="regularWorkCount">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.regularWorkCount" placeholder="请输入正常打开次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="迟到次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lateCount">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.lateCount" placeholder="请输入迟到次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="早退次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leaveCount">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.leaveCount" placeholder="请输入早退次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="旷工次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="absentWorkCount">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.absentWorkCount" placeholder="请输入旷工次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="缺卡次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="missingCount">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.missingCount" placeholder="请输入缺卡次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地点异常" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="locationAnomalyCount">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.locationAnomalyCount" placeholder="请输入地点异常" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设备异常" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unitExceptionCount">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.unitExceptionCount" placeholder="请输入设备异常" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作日加班(分钟)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workdayOverMin">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.workdayOverMin" placeholder="请输入工作日加班(分钟)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="节假日加班(分钟)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="holidaysOverMin">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.holidaysOverMin" placeholder="请输入节假日加班(分钟)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="休息日加班(分钟)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="restdaysOverMin">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.restdaysOverMin" placeholder="请输入休息日加班(分钟)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="补卡次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="replenishmentCardCount">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.replenishmentCardCount" placeholder="请输入补卡次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="外勤次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fieldWorkCount">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.fieldWorkCount" placeholder="请输入外勤次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="外出小时" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outDuration">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.outDuration" placeholder="请输入外出小时" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出差天数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="travelDuration">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.travelDuration" placeholder="请输入出差天数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="年假天数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="annualLeaveDuration">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.annualLeaveDuration" placeholder="请输入年假天数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事假(小时)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="askLeaveDuration">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.askLeaveDuration" placeholder="请输入事假(小时)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="病假(小时)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sickLeaveDuration">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.sickLeaveDuration" placeholder="请输入病假(小时)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="调休假(小时)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leaveDuration">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.leaveDuration" placeholder="请输入调休假(小时)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="婚假天数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="marriageLeaveDuration">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.marriageLeaveDuration" placeholder="请输入婚假天数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产假天数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maternityLeaveDuration">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.maternityLeaveDuration" placeholder="请输入产假天数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="陪产假天数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accompanyingLaborDuration">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.accompanyingLaborDuration" placeholder="请输入陪产假天数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="哺乳假天数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="breastfeedingLeaveDuration">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.breastfeedingLeaveDuration" placeholder="请输入哺乳假天数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ErpEmployeeAttendanceMonthForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/api/erp/hr/attendance/erpEmployeeAttendanceMonth/add",
          edit: "/api/erp/hr/attendance/erpEmployeeAttendanceMonth/edit",
          queryById: "/api/erp/hr/attendance/erpEmployeeAttendanceMonth/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
